﻿using CPPEI.ETL.DataServiceInterface;
using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ENT = CPPEI.ETL.Domain.Entities;
using MOD = CPPEI.ETL.Domain.Models;
using SER = CPPEI.ETL.Domain.Services;

namespace CPPEI.ETL.WebApi.DataVerificationRule
{
    [CPPEI.WebApi.AuthPostAction("DVR", "Create", "1.0")]
    public class CreateAction : BaseAction<CreateParams, CreateResult>
    {
        protected override ActionResult<CreateResult> OnExecute(ActionContext context, 
            SysParameters sysParameters,
            CreateParams opParams)
        {
            SER.DataVerificationRuleService service = new SER.DataVerificationRuleService();
            ServiceResult result = service.Create(context.UserId, opParams.DataTableId, opParams.Caption, opParams.Condition, opParams.Type, opParams.ParameterSettings);
            if(result.IsSuccess)
            {
                return new ActionResult<CreateResult>(new CreateResult());
            }
            else
            {
                return new ActionResult<CreateResult>(result.IsSuccess, result.ErrorCode, result.Message, null);
            }
        }
    }

    public class CreateParams
    {
        [Parameter]
        public Guid DataTableId { get; set; }

        [Parameter]
        public string Condition { get; set; }

        public string Caption { get; set; }

        /// <summary>
        /// 规则类型，1脚本，2插件,3存储过程
        /// </summary>
        [Parameter]
        public int Type { get; set; }

        /// <summary>
        /// 参数设置(name,value,name,value)
        /// </summary>
        public string ParameterSettings { get; set; }
    }

    public class CreateResult
    {
    }
}
